package com.example.test.dao;

import com.example.test.dto.ActorRole;
import com.example.test.entities.Roles;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface RoleRepository extends CrudRepository<Roles,Long> {
    @Override
    List<Roles> findAll();
    @Query(nativeQuery = true,value = "SELECT r.name, r.relation , COUNT(ar.role_id) AS roleActorCount " +
            "FROM  role  AS r LEFT JOIN role_actor AS ar ON ar.actor_id = r.role_id " +
            " GROUP BY r.name, r.relation ORDER BY 3 desc;")
    List<ActorRole> actorRole();
}
